/**
 * @param {number[]} nums
 * @return {number[]}
*/
var sortArrayByParityII = function(nums) {
  let odd = [], even = [], result = [];
  for(let i = 0; i < nums.length; i++) {
    if(nums[i] % 2) {
      odd.push(nums[i]);
    } else {
      even.push(nums[i]);
    }
  }
  odd.sort((a, b) => a - b);
  even.sort((a, b) => a - b);
  for(let i = 0; i < odd.length; i++) {
    result.push(even[i]);
    result.push(odd[i]);
  }
  return result;
};
let nums = [4,2,5,7];
console.log(sortArrayByParityII(nums));
nums = [2,3];
console.log(sortArrayByParityII(nums));
